<?php

namespace catchAdmin\basics\controller;

use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\basics\model\SuperviseMode as SuperviseModeModel;
use think\Response;
use catcher\CatchAuth;

class SuperviseMode extends CatchController
{
    
    protected $superviseModeModel;
    
    /**
     *
     * @time 2022/03/04 14:26
     * @param SuperviseModeModel $superviseModeModel
     * @return mixed
     */
    public function __construct(SuperviseModeModel $superviseModeModel)
    {
        $this->superviseModeModel = $superviseModeModel;
    }
    
    /**
     * 列表
     * @time 2022/03/04 14:26
     * @return Response
     */
    public function index(CatchAuth $auth)
    {
        $user=$auth->user();
        return CatchResponse::paginate($this->superviseModeModel->getList($user['id']));
    }

    /**
     * 新建
     * @time 2022/03/02 10:39
     * @throws \think\db\exception\DbException
     * @return \think\response\Json
     */
    public function create(CatchAuth $auth,Request $request)
    {
        $user = $auth->user();
        $params = $request->filterEmptyField()->post();
        $params['tenant_id'] = $user['id'];
        return CatchResponse::success($this->superviseModeModel->storeBy($params),'新建成功');
    }
    
    /**
     * 更新
     * @time 2022/03/04 14:26
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update(Request $request) : Response
    {
        $params = $request->filterEmptyField()->post();
        return CatchResponse::success($this->superviseModeModel->updateBy($params['id'],$params),'更新成功');
    }
    
    /**
     * 删除
     * @time 2022/03/04 14:26
     * @param $id
     * @return Response
     */
    public function delete(Request $request) : Response
    {
        $id = $request->post('id');
        return CatchResponse::success($this->superviseModeModel->deleteBy($id),'删除成功');
    }
}